class Solution(object):
    def solve(self, board):
        """
        :type board: List[List[str]]
        :rtype: void Do not return anything, modify board in-place instead.
        """
        nRow = len(board)
        if nRow==0: return
        nCol = len(board[0])

        record = [[None for _ in range(nCol)] for _ in range(nRow)]
        def capture(r, c):
            queue = [(r,c)]
            while queue:
                newQueue = []
                for r,c in queue:
                    if not(0<=r<nRow and 0<=c<nCol): continue
                    if record[r][c]!=None: continue
                    if board[r][c]=='X':
                        record[r][c]=False 
                        continue
                    else:
                        record[r][c]=True
                    newQueue.append((r-1,c))
                    newQueue.append((r+1,c))
                    newQueue.append((r,c-1))
                    newQueue.append((r,c+1))
                queue = newQueue
        
        if nRow>1:
            for r in range(nRow-1): capture(r,nCol-1)
            for r in range(1,nRow)[::-1]: capture(r,0)
        else:
            for c in range(nCol): capture(0,c)
        if nCol>1:
            for c in range(nCol-1): capture(0,c)
            for c in range(1,nCol)[::-1]: capture(nRow-1,c)
        else:
            for r in range(nRow): capture(r,0)

        for r in range(nRow):
            for c in range(nCol):
                board[r][c] = 'O' if record[r][c]==True else 'X'

input = [['O']]
Solution().solve(input)